{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "基于上节得到的模型，我们可进一步编写Python代码，对X_test对应的输出数据进行预测。需要注意的是，直接得到的预测结果是处于标准化的数据空间中的，需要将其还原成原始数据空间的值，结果才有意义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import pickle\n",
    "\n",
    "with open('data/model.pkl', 'rb') as f:\n",
    "    model = pickle.load(f)\n",
    "\n",
    "with open('data/X_test.pkl', 'rb') as f:\n",
    "    X_test = pickle.load(f)\n",
    "\n",
    "with open('data/t0_ptp.pkl', 'rb') as f:\n",
    "    t0_ptp = pickle.load(f)\n",
    "    \n",
    "with open('data/t0_min.pkl', 'rb') as f:\n",
    "    t0_min = pickle.load(f)\n",
    "    \n",
    "pred_y = model.predict(X_test)\n",
    "preddf = pred_y*t0_ptp[0:96]+t0_min[0:96]\n",
    "\n",
    "with open('data/preddf.pkl', 'wb') as f:\n",
    "    pickle.dump(preddf, f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如代码所示，将模型的预测结果pred_y乘以t0_ptp再加上t0_min，即可对数据进行还原。preddf即是最终得到的预测数据，可打印其值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[16.33048152, 14.60479507, 17.54907301, ..., 25.60496482,\n",
       "        24.20742414, 23.33218088],\n",
       "       [18.60025231, 19.61755758, 17.18575891, ..., 19.75872056,\n",
       "        23.30681835, 19.76247044],\n",
       "       [19.91520072, 20.11145205, 16.49641613, ..., 21.98817124,\n",
       "        22.86349272, 19.88845592],\n",
       "       ...,\n",
       "       [21.15874381, 19.27915385, 16.93204082, ..., 26.65473438,\n",
       "        21.00806721, 19.88542461],\n",
       "       [17.2611691 , 13.49040936, 13.000749  , ..., 24.53293451,\n",
       "        20.79611776, 22.17191952],\n",
       "       [18.92261238, 18.51137825, 15.07442732, ..., 17.81154147,\n",
       "        24.52319439, 18.75483356]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "preddf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(30, 96)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "preddf.shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
